<template>
  <div class="login">
    <el-card class="login-card">
      <template #header>
        <span>上下川岛车渡现场出票系统</span>
      </template>
      <el-form :model="form" label-width="auto">
        <el-form-item label="帐号">
          <el-input v-model="form.userName" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"  show-password type="password"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSubmit" class="btn">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { useUser } from "@/stores/user";
import { reactive } from "vue";
import { useRouter } from "vue-router";
import { ElMessage } from 'element-plus'
const router = useRouter();
const userStore = useUser();
const form = reactive({
  userName: "",
  password: "",
});
const handleSubmit = () => {
  userStore.handleLogin(form.userName, form.password).then(res => {
    if (res.status) {
      if(userStore.scene_only_query=='1'){
        router.push({
          name: 'onlysearch'
        })
      }else{
        router.push({
          name: 'order'
        })
      }
      
    } else {
      ElMessage({ message: res.msg, duration: 3000, type: 'error' })
    }
  })
};
</script>

<style scoped>
.login {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: row;
  background-color: rgb(154, 183, 247);
}
.btn{
  width: 100%;
}
.box {
  height: 350px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  background-color: rgba(218, 218, 218, 0.3);
}

.login-card {
  margin: 30px 0;
}
.title {
  color: #f5f5f5;
  font-size: 30px;

  text-shadow: 2px 2px 5px #929292;
}
</style>